package server

import (
	"awesome-devops/applications/rpc/define"
	"awesome-devops/applications/rpc/services"
	"awesome-devops/applications/tools"
	"gitee.com/jjawesomejj/awesome-rpc/server"
	"google.golang.org/grpc"
	"strconv"
)

type RpcServer struct {
	ListenPort int
}

func (rpcServer *RpcServer) Run() {
	grpcServer := server.GrpcServer{
		Port: rpcServer.ListenPort,
	}
	grpcServer.RegisterService(server.ServiceDesc{
		Name: "执行发布任务",
	}, func(rpcServer *grpc.Server) {
		define.RegisterRunnerServiceServer(rpcServer, &services.Runner{})
	})

	grpcServer.RegisterService(server.ServiceDesc{
		Name: "获取节点信息",
	}, func(rpcServer *grpc.Server) {
		define.RegisterNodeServiceServer(rpcServer, &services.NodeResource{})
	})
	grpcServer.OnServerStart(func() {
		tools.GetLogger().Info("rpc 服务启动" + ":" + strconv.Itoa(rpcServer.ListenPort))
	})
	grpcServer.Start()
}
